﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using BBECServiceBusAdapter_CodeGenLib.ViewForms.Constituent;
using BBECServiceBusAdapter.Activities;

namespace BBECServiceBusAdapter.Helper_Activities.Outbound
{
    public sealed class ViewConstituent : CodeActivity
    {
        // Define an activity input argument of type string
        public InOutArgument<BBECServiceBusAdapter.ConstituentDataContract> ConstitData { get; set; }
        public InArgument<Guid> ConstituentGuid { get; set; }
        public OutArgument<DateTime> DateAdded { get; set; }
        public OutArgument<DateTime> DateChanged { get; set; }
        public OutArgument<String> ChangedBy { get; set; }


        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            //string text = context.GetValue(this.Data.).ToString;
            BBECServiceBusAdapter.ConstituentDataContract outData = context.GetValue(this.ConstitData);
            Guid inConstitGuid = context.GetValue(this.ConstituentGuid);

            ConstituentBasicInfoData frmData = ConstituentBasicInfo.LoadData(new Blackbaud.AppFx.WebAPI.AppFxWebServiceProvider(Blackbaud.AppFx.Workflow.CatalogActivities.WebApiUtility.GetAppFxWebApiProvider(context).ConnectionString), inConstitGuid.ToString());
            
            outData.LastOrOrganizationName = frmData.KEYNAME;
            outData.FirstName = frmData.FIRSTNAME;
            outData.MiddleName = frmData.MIDDLENAME;
            outData.MaidenName = frmData.MAIDENNAME;
            outData.Nickname = frmData.NICKNAME;
            outData.ID = frmData.THELOOKUPID;
            outData.ConstituentID = frmData.THELOOKUPID;
            outData.LookupID = frmData.THELOOKUPID;
            outData.Title1 = frmData.TITLE;
            outData.Title2 = frmData.TITLE2;
            outData.Suffix1 = frmData.SUFFIX;
            //outData.Suffix2 = frmData.SUFFIX2;
            switch (frmData.GENDER.ToUpper()) {
                case "FEMALE":
                    outData.Gender = BBECServiceBusAdapter.ConstituentDataContractExtensions.ConstituentGenderType.Female;
                    break;
                case "MALE":
                    outData.Gender = BBECServiceBusAdapter.ConstituentDataContractExtensions.ConstituentGenderType.Female;
                    break;
                default:
                    outData.Gender = BBECServiceBusAdapter.ConstituentDataContractExtensions.ConstituentGenderType.Unknown;
                    break;
            }

            context.SetValue(this.DateAdded, (DateTime)frmData.DATEADDED);
            context.SetValue(this.DateChanged, (DateTime)frmData.DATECHANGED);
            context.SetValue(this.ChangedBy, frmData.CHANGEDBYUSERNAME);
           //WriteEventLog log = new WriteEventLog()
           //log.

            //if (DateTime.TryParse(frmData.BIRTHDATE, outData.Birthdate)) {}
            outData.IsInactive = (bool)frmData.ISINACTIVE; 
            outData.WebAddress = frmData.WEBADDRESS;
 
            if ((bool)frmData.ISORGANIZATION)
                outData.ConstituentType =ConstituentDataContractExtensions.ConstituentType.Organization;

            outData.MaritalStatus = frmData.MARITALSTATUS;
            //@MARITALSTATUSCODEID  = c.MARITALSTATUSCODEID,
            
    //@ISCONSTITUENT        = c.ISCONSTITUENT, 
    //@AGE                  = c.AGE



        }
    }
}
